<html><head><title>AESEncoder</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<font face="Verdana, sans-serif" size="2"><p align="center"><b><font size="4">AESEncoder()</font></b></p>
<p><b>Syntax</b></p><blockquote>
Result = <font color="#3A3966"><b>AESEncoder</b></font>(*Input, *Output, Size, *Key, Bits, *InitializationVector [, Mode])</blockquote>

</blockquote>
<b>Description</b><br><blockquote>

Encodes the specified input buffer using the AES algorithm into the output buffer. 

</blockquote><p><b>Parameters</b></p><blockquote>
<style type="text/css">
table.parameters { border-spacing: 0px; border-style: none; border-collapse: collapse; }
table.parameters td { border-width: 1px; padding: 6px; border-style: solid; border-color: gray; vertical-align: top; font-family:Arial; font-size:10pt; }
</style>
<table width="90%" class="parameters">
<tr><td width="10%"><i>*Input</i></td>
<td width="90%"> 
The input buffer with the plain data. 

</td></tr>
<tr><td><i>*Output</i></td>
<td> 
The output buffer which will receive the encoded data. It has to be different than the 
input buffer. 

</td></tr>
<tr><td><i>Size</i></td>
<td> 
The amount of bytes to encode. It has to be at least 16 bytes. To encode something 
smaller, padding has to be added before the encoding. 

</td></tr>
<tr><td><i>*Key</i></td>
<td> 
A buffer containing the key for encoding. 
Its size depends of the 'Bits' parameter: l6 bytes for 128-bit encryption, 24 bytes for 192 bit 
and 32 bytes for 256-bit. 

</td></tr>
<tr><td><i>Bits</i></td>
<td> 
The size of the key used by the ciphering. Valid values are 128, 192 and 256. 

</td></tr>
<tr><td><i>*InitializationVector</i></td>
<td> 
The InitializationVector is a random data block, used to initialize the ciphering 
to avoid breach in decoding (only needed when using the <font color="#924B72">#PB_Cipher_CBC</font> mode). 
The initialization vector is always 16 bytes long. 

</td></tr>
<tr><td><i>Mode (optional)</i></td>
<td> 
This can be one of the following value: 
<pre><font face="Courier New, Courier, mono"size="2">  <font color="#924B72">#PB_Cipher_CBC</font>: Default mode of encoding (Cipher Block Chaining). Needs an '*InitializationVector'.
                  Recommended as more secure than ECB mode.
  <font color="#924B72">#PB_Cipher_ECB</font>: Alternative mode (Electronic CodeBook). It doesn't use a random value or chaining 
                  (each block is ciphered independently) making it less strong the CBC.
</font></pre>

</td></tr>
</table>
</blockquote><p><b>Return value</b></p><blockquote>

Returns nonzero if the encoding was successful, zero otherwise. 

</blockquote><p><b>Remarks</b></p><blockquote>

AES is an industry class cipher algorithm and is good balanced between speed and security. Here is 
the Wikipedia introduction about AES: 
'In cryptography, the Advanced Encryption Standard (AES) is an encryption standard adopted by the U.S. government. 
The standard comprises three block ciphers, AES-128, AES-192 and AES-256, adopted from a larger collection originally 
published as Rijndael. Each AES cipher has a 128-bit block size, with key sizes of 128, 192 and 256-bit, respectively. 
The AES ciphers have been analyzed extensively and are now used worldwide.' 
<br>
<br>
PureBasic uses a RFC compliant implementation of AES. 
More information can be found in the RFC 3602: <a href="http://www.ietf.org/rfc/rfc3602.txt">http://www.ietf.org/rfc/rfc3602.txt</a>. 

</blockquote><p><b>Example:</b> CBC</p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">  <font color="#3A3966">; Should be compiled in ascii mode</font>
  <font color="#3A3966">;</font>
  String$ = &quot;Hello this is a test for AES&quot;
  
  *CipheredString   =<font color="#3A3966"> AllocateMemory</font>(<font color="#3A3966">Len</font>(String$)+1) <font color="#3A3966">; Space for the string and its</font>
  *DecipheredString =<font color="#3A3966"> AllocateMemory</font>(<font color="#3A3966">Len</font>(String$)+1) <font color="#3A3966">; null terminating character (ASCII mode)</font>
  
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">AESEncoder</font>(@String$, *CipheredString,<font color="#3A3966"> Len</font>(String$), ?Key, 128, ?InitializationVector)
    <b><font color="#3A3966">Debug</font></b> &quot;Ciphered: &quot;+<font color="#3A3966">PeekS</font>(*CipheredString)
    
<font color="#3A3966">    AESDecoder</font>(*CipheredString, *DecipheredString,<font color="#3A3966"> Len</font>(String$), ?Key, 128, ?InitializationVector)
    <b><font color="#3A3966">Debug</font></b> &quot;Deciphered: &quot;+<font color="#3A3966">PeekS</font>(*DecipheredString)
  <b><font color="#3A3966">EndIf</font></b>

  <b><font color="#3A3966">DataSection</font></b>
    Key:
      <b><font color="#3A3966">Data</font></b>.b $06, $a9, $21, $40, $36, $b8, $a1, $5b, $51, $2e, $03, $d5, $34, $12, $00, $06
  
    InitializationVector:
      <b><font color="#3A3966">Data</font></b>.b $3d, $af, $ba, $42, $9d, $9e, $b4, $30, $b4, $22, $da, $80, $2c, $9f, $ac, $41
  <b><font color="#3A3966">EndDataSection</font></b>
  
</font></pre>

</blockquote><p><b>Example:</b> ECB</p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">  <font color="#3A3966">; Should be compiled in ascii mode</font>
  <font color="#3A3966">;</font>
  String$ = &quot;Hello this is a test for AES&quot;
  
  *CipheredString   =<font color="#3A3966"> AllocateMemory</font>(<font color="#3A3966">Len</font>(String$)+1) <font color="#3A3966">; Space for the string and its</font>
  *DecipheredString =<font color="#3A3966"> AllocateMemory</font>(<font color="#3A3966">Len</font>(String$)+1) <font color="#3A3966">; null terminating character (ASCII mode)</font>
  
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">AESEncoder</font>(@String$, *CipheredString,<font color="#3A3966"> Len</font>(String$), ?Key, 128, 0, <font color="#924B72">#PB_Cipher_ECB</font>)
    <b><font color="#3A3966">Debug</font></b> &quot;Ciphered: &quot;+<font color="#3A3966">PeekS</font>(*CipheredString)
    
<font color="#3A3966">    AESDecoder</font>(*CipheredString, *DecipheredString,<font color="#3A3966"> Len</font>(String$), ?Key, 128, 0, <font color="#924B72">#PB_Cipher_ECB</font>)
    <b><font color="#3A3966">Debug</font></b> &quot;Deciphered: &quot;+<font color="#3A3966">PeekS</font>(*DecipheredString)
  <b><font color="#3A3966">EndIf</font></b>

  <b><font color="#3A3966">DataSection</font></b>
    Key:
      <b><font color="#3A3966">Data</font></b>.b $06, $a9, $21, $40, $36, $b8, $a1, $5b, $51, $2e, $03, $d5, $34, $12, $00, $06
  <b><font color="#3A3966">EndDataSection</font></b>
  
</font></pre>

</blockquote><p><b>See Also</b></p><blockquote>

<a href="aesdecoder.html">AESDecoder()</a>, <a href="startaescipher.html">StartAESCipher()</a> 

</Blockquote><p><b>Supported OS </b><Blockquote>All</Blockquote></p><center><- <a href=aesdecoder.html>AESDecoder()</a> - <a href="index.html">Cipher Index</a> - <a href="addcipherbuffer.html">AddCipherBuffer()</a> -><br><br>

</body></html>